package ru.gerunn.silent.client;

import java.io.IOException;
import java.net.UnknownHostException;

import ru.gerunn.silent.common.ConsoleReader;
import ru.gerunn.silent.common.ConsoleWriter;
import ru.gerunn.silent.common.RW;
import ru.gerunn.silent.common.Reader;
import ru.gerunn.silent.common.SSLSocketReader;
import ru.gerunn.silent.common.SSLSocketWriter;
import ru.gerunn.silent.common.Writer;
import ru.gerunn.silent.listener.SilentListener;

public class ConsoleClientApp {

	public static void main(String[] args) {
		System.setProperty("javax.net.ssl.trustStore", "keystore.jks");
		System.setProperty("javax.net.ssl.trustStorePassword", "Hjz3&5");

		try {
			Client client = new Client();

			client.addEventListener("NoClientServerRW", new SilentListener() {
				public void doEvent() {
					System.out.println("NoClientServerRW");
					Thread.currentThread().interrupt();
				}
			});

			client.addEventListener("NoServerClientRW", new SilentListener() {
				public void doEvent() {
					System.out.println("NoServerClientRW");
				}
			});

			Writer socketWriter = new SSLSocketWriter(client.getSocket());
			Reader socketReader = new SSLSocketReader(client.getSocket());
			Writer consoleWriter = new ConsoleWriter();
			Reader consoleReader = new ConsoleReader();

			client.setClientServerRW(new RW(consoleReader, socketWriter));
			client.setServerClientRW(new RW(socketReader, consoleWriter));

			client.start();
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
